﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GoShopping.Model;

namespace GoShopping.BLL
{
    /// <summary>
    /// 主页新闻维护类
    /// </summary>
    public class ThemeLinkBean
    {
        /// <summary>
        /// 获取所有主页新闻列表
        /// </summary>
        /// <returns></returns>
        public IList<ThemeLink> GetAllThemeLink()
        {
            return Databases.DBGoShopping.Select(GoShoppingNBear.ThemeLink).OrderBy(GoShoppingNBear.ThemeLink.Order.Asc).ToList<ThemeLink>();
        }

        /// <summary>
        /// 删除主页新闻
        /// </summary>
        /// <param name="themeLinkID"></param>
        /// <returns></returns>
        public bool DelThemeLink(string themeLinkID)
        {
            int i = Databases.DBGoShopping.Delete(GoShoppingNBear.ThemeLink).Where(
                GoShoppingNBear.ThemeLink.ID == themeLinkID).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 添加
        /// </summary>
        /// <param name="tl"></param>
        /// <returns>创建的自增主键</returns>
        public int AddThemeLink(ThemeLink tl)
        {
            return Databases.DBGoShopping.Insert(GoShoppingNBear.ThemeLink).AddColumn(
                GoShoppingNBear.ThemeLink.LinkUrl, tl.LinkUrl).AddColumn(
                GoShoppingNBear.ThemeLink.Order, tl.Order).AddColumn(
                GoShoppingNBear.ThemeLink.Title, tl.Title).ExecuteReturnAutoIncrementID(
                GoShoppingNBear.ThemeLink.ID);
        }

        /// <summary>
        /// 更新一个主页新闻
        /// </summary>
        /// <param name="themelink"></param>
        /// <returns></returns>
        public bool UpdateThemeLink(ThemeLink themelink)
        {
            int i = Databases.DBGoShopping.Update(GoShoppingNBear.ThemeLink).AddColumn(
                GoShoppingNBear.ThemeLink.LinkUrl, themelink.LinkUrl).AddColumn(
                GoShoppingNBear.ThemeLink.Order, themelink.Order).AddColumn(
                GoShoppingNBear.ThemeLink.Title, themelink.Title).Where(
                GoShoppingNBear.ThemeLink.ID == themelink).Execute();
            if (i > 0)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
